<?php
/*
Overmundo, cultura de todo o Brasil
Desenvolvido pela Tecnopop para o Núcleo de Idéias Movimento
Copyright (C) 2006  Núcleo de Idéias Movimento

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/


	$file = $_GET["file"];
    $filedir =  "../uploads/agenda/audio/";
    $path =  $filedir . $file;
//	echo $path;

    //check that this file exists and that it doesn't include
    //any special characters
    if(!is_file($path) OR !eregi('^[A-Z_0-9][A-Z_0-9.]*$', $file))
    {
        header("Location: error.php");
        exit();
    }

    /*
    ** //check that the user has permission to download file
    ** if(user does not have permission)
    ** {
    **     //redirect to error page
    **     header("Location: error.php");
    **     exit();
    ** }
    */

    $mimetype = array(
        'doc'=>'application/msword',
        'torrent'=>'application/x-bittorrent',
        'jpg'=>'image/pjpeg',
        'pdf'=>'application/pdf',
        'txt'=>'text/plain',
        'xls'=>'application/vnd.ms-excel',
		'mp3'=>'audio/mpeg',
		
		'rtf'=>'text/plain',
		'mpeg'=>'text/plain',
		'zip'=>'application/zip',
		'ogg'=>'text/plain',
		'ods'=>'text/plain',
		'sxw'=>'text/plain',
		'ppt'=>'text/plain',
		'pps'=>'text/plain',
		
		
        );

    $p = explode('.', $file);
    $pc = count($p);

    //send headers
    //if(($pc > 1) AND isset($mimetype[$p[$pc - 1]]))
    //{
        //display file inside browser
     //   header("Content-type: " . $mimetype[$p[$pc - 1]] . "\n");
    //}
    //else
    //{
        //force download dialog
        header("Content-type: application/octet-stream\n");
        header("Content-disposition: attachment; filename=\"$file\"\n");
    //}
    header("Content-transfer-encoding: binary\n");
    header("Content-length: " . filesize($path) . "\n");

    //send file contents
    $fp=fopen($path, "r");
    fpassthru($fp);
?> 